﻿using DFGJ.WMS_PDA.WebAPI.Extensions;
using DFGK_WMS.IRepository;
using DFGK_WMS.Model.DTO;
using DFGK_WMS.Model.Models;
using DFGK_WMS.WebAPI.Controllers.Result;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace DFGJ.WMS_PDA.WebAPI.Controllers.PDA
{
    /// <summary>
    /// 盘点单
    /// </summary>
    [ApiController]
    [Route("api/[controller]/[action]")]
    [ApiExplorerSettings(IgnoreApi = false, GroupName = nameof(ApiVersions.V1))]
    [AllowAnonymous]
    
    public class PDAStocktakingController : ApiBaseController
    {
        public PDAStocktakingController(ITStocktakingOrderRepository stoService)
        {
            StoService = stoService;
        }

        public ITStocktakingOrderRepository StoService { get; }


        /// <summary>
        /// 提交（有网）
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>'

        [HttpPost]
        public IActionResult UpdTStocktakingOrderState(TStocktakingOrderDetail m)
        {
            if (m.Id <= 0)
            {
                return Ok(BaseResult.Result("400", "Id有误！"));
            }
            string message;         
            bool IsOK = StoService.UpTSocktakingStatus(m, out message);
            if (IsOK)
            {
                return Ok(BaseResult.Result(true, "修改成功！", "200"));
            }

            return Ok(BaseResult.Result(false, message, "500"));
        }


        /// <summary>
        /// 获取状态为2的盘点单
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetStocktakingList()
        {
            var list = StoService.GetStocktakingList();
            if (list.Count >= 0)
            {
                return Ok(BaseResult.Result(list, "查询成功！", "200"));
            }
            return Ok(BaseResult.Result(null, "查询失败", "500"));
        }

        /// <summary>
        /// 根据单号查询详情
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetStocktakingDetailList(string orderSn)
        {
            var list = StoService.GetStocktakingDetailList(orderSn);
            if (list.Count >= 0)
            {
                return Ok(BaseResult.Result(list, "查询成功！", "200"));
            }
            return Ok(BaseResult.Result(null, "查询失败", "500"));
        }
    }
}
